import api from '../../http/apis/apis'
export default {
    namespaced: true,
    //下面写请求
    state: {
        currentPage: 1,
        pageSize: 3,
        //保存销售员的所有的订单
        OrderData: {
            total: 0,
            totalPages: 0,
            data: [],

        },
        update: {},//修改
        typeDate: {},//查找类型的顶大
        clients:{},//客户下拉框
    },
    mutations: {
        changeOrder(state, val) {
            state.OrderData = val
            state.clients=val.data
        },
        //改变当前页
        setCurrent(state, newcurrent) {
            state.currentPage = newcurrent
        },
        //每页显示数量
        setPageSize(state, newpagesize) {
            state.pageSize = newpagesize
        },
        //修改订单的第一步
        changeUpdate(state, newval) {
            state.update = newval
        },
        changeTypeDate(state, newval) {
            state.typeDate = newval
        }
    },
    actions: {
        //销售员订单的列表
        async getSalesOrder(context, { type, value } = {}) {
            let _id = "5f6aa2a0f97e0d3fb82c578a";
            const { data } = await api.order.getSalesOrder({
                type,
                value,
                _id,
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
            })
            if (data.status > 0) {
                context.commit('changeOrder', data.data)
            }
        },
        //删除订单
        async deletOrder(context, _id) {
            const { data } = await api.order.deletOrder({ _id })
            if (data.status > 0) {
                context.dispatch('getSalesOrder')
            }
        },
        //获取一个订单信息
        async getOrder(context, _id) {
            const { data } = await api.order.getOrder({ _id });
            console.log('订单信息',data);
            if (data.status > 0) {
                context.commit('changeUpdate', data.data)
                return data.data
            }
        },
        //修改订单
        async updateOrderSuccess(context, val) {
            const { data } = await api.order.updateOrderSuccess(val);
            if (data.status) {
                context.dispatch('getSalesOrder')
            }
        },
        //查找订单
        async findTypeOrder(context, val) {
            const { data } = await api.order.findTypeOrder(val)
            if (data.status) {
                context.commit('changeTypeDate', data.data)
            }
        }
    }

}